package com.falcon.authority.controller;

import com.falcon.authority.domain.po.UserRolePO;
import com.falcon.authority.domain.req.UserRoleQuery;
import com.falcon.authority.domain.req.UserRoleRequest;
import com.falcon.authority.service.IUserRoleService;
import com.falcon.core.controller.IBaseController;
import com.falcon.core.domain.BasePager;
import com.falcon.core.domain.BaseResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/authority/userRole")
@Tag(name = "UserRoleController", description = "用户角色关系-接口")
public class UserRoleController  implements IBaseController {

    @Autowired
    private IUserRoleService userRoleService;

    @Operation(summary = "新增")
    @PostMapping("/save")
    public BaseResponse<Long> save(@Valid @RequestBody UserRoleRequest request) {

        Long id =  this.userRoleService.save(request);

        return BaseResponse.success(id);
    }

    @Operation(summary = "修改")
    @PutMapping("/update/{id}")
    public BaseResponse<Boolean> update(@PathVariable Long id, @Valid @RequestBody UserRoleRequest request) {

        Boolean success =  this.userRoleService.update(id, request);

        return BaseResponse.success(success);
    }

    @Operation(summary = "删除")
    @DeleteMapping("/delete/{id}")
    public BaseResponse<Boolean> deleteById(@PathVariable Long id) {

        Boolean success =  this.userRoleService.deleteById(id);

        return BaseResponse.success(success);
    }

    @Operation(summary = "批量删除")
    @PostMapping("/batchDelete")
    public BaseResponse<Integer> batchDelete(@RequestBody List<Long> ids) {

        Integer num =  this.userRoleService.batchDelete(ids);

        return BaseResponse.success(num);
    }

    @Operation(summary = "查询基本信息")
    @GetMapping("/{id}")
    public BaseResponse<UserRolePO> detail(@PathVariable Long id) {

        UserRolePO userRoleDo =  this.userRoleService.queryById(id);

        return BaseResponse.success(userRoleDo);
    }


    @Operation(summary = "列表查询")
    @PostMapping("/list")
    public BaseResponse<List<UserRolePO>> list(@RequestBody UserRoleQuery request) {

        List<UserRolePO> list =  this.userRoleService.queryList(request);

        return BaseResponse.success(list);
    }

    @Operation(summary = "分页查询")
    @PostMapping("/pager")
    public BaseResponse<BasePager<UserRolePO>> pager(@RequestBody UserRoleQuery request) {

        BasePager<UserRolePO> pager =  this.userRoleService.queryPager(request);

        return BaseResponse.success(pager);
    }


}
